#pragma once
#include "..\ZGlobalFile\ZLibIncludeHeader.h"
#include "ZTcpReadHelper.h"

class ZTcpPackReactorMgr;

typedef std::vector<QTcpSocket*> vecTcpSocket;

class ZTCPNETLIB ZTcpServerSocket : public QTcpServer
{
	Q_OBJECT
public:
	ZTcpServerSocket(ZTcpPackReactorMgr* pReactorMgr);
	~ZTcpServerSocket();

public:
	const vecTcpSocket& GetAllClient() const { return m_vecClient; }

protected:
	virtual void OnAcceptNewConnection(QTcpSocket* pNewConSock) {};
	virtual void OnDisConnectedConnection(QTcpSocket* pNewConSock) {};

protected slots:
	void _acceptConnection();
	void OnClientDisConnected(); 

	void _onRecvClientMsg();
	void OnClientError(QAbstractSocket::SocketError socketError);

private:
	ZTcpReadHelper*	_getReadHelp(QTcpSocket* pClientSock);
	bool			_deleteReadHelp(QTcpSocket* pClientSock);
	void			_deleteAllReadHelp();

protected:
	ZTcpPackReactorMgr*			m_pReactorMgr;
	vecTcpSocket				m_vecClient;
	vecTcpReadHelper			m_vecReadHelper;
};